package com.zdkj.subway.stm.util;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.zdkj.common.core.util.SpringContextHolder;

import java.util.List;
import java.util.Map;
/**
 * 车票名称
 *
 * @author Jiaju Zhuang
 */
public class CardTypeParamConverter implements Converter<String> {
    @Override
    public Class supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
                                    GlobalConfiguration globalConfiguration) {
        throw new UnsupportedOperationException("Cannot convert images to string");
    }

    @Override
    public CellData convertToExcelData(String value, ExcelContentProperty contentProperty,
                                       GlobalConfiguration globalConfiguration) throws Exception {
        String sql = "SELECT  SUB_NAME as subname FROM sw_pm_ticket_card_type_param  WHERE DEL_FLAG=0 AND SUB_EN_NAME = '"+value+"' ";
        List<Map<String,Object>> listReturn  = JdbcUtil.exeSqlQuery(sql);
		if(listReturn!=null && listReturn.size()>0){
			Map<String,Object> map = listReturn.get(0);
			String queryValue  = String.valueOf(map.get("subname"));
			return new CellData(queryValue);

		}
		return new CellData(value);
    }

}
